<template>
  <div class="song-list warpper">
    <!-- 歌单收藏、评论信息 -->
    <div class="play-info">
      <li @click="msg('订阅')">
        <van-icon name="newspaper-o" />
        <span>{{ playlist.subscribedCount }}</span>
      </li>
      <li @click="msg('评论')">
        <van-icon name="comment-o" />
        <span>{{ playlist.commentCount }}</span>
      </li>
      <li @click="shareRef.showShare = true">
        <van-icon name="share-o" />
        <span>{{ playlist.shareCount }}</span>
      </li>
    </div>

    <!-- 歌曲列表 -->
    <div class="list">
      <div class="title">
        <div class="play-all" @click="playAll(songlist)">
          <van-icon name="play-circle-o" color="#e60012" />
          <span>播放全部 ( {{ songlist.length }} )</span>
        </div>
      </div>
      <ul>
        <van-skeleton class="skeleton-margin-bottom" title :row="1" v-for="item in 5" :loading="showLoadingIcon" />
        <li v-for="item, index in songlist" :key="index">
          <div class="index font-fu">{{ index + 1 }}</div>
          <!-- 歌曲名 -->
          <div class="song-detail" @click="playSong(songlist, index)">
            <div class="song-title">
              {{ item.name }}
            </div>
            <div class="song-info font-fu">
              <span v-for="ar in item.ar">{{ ar.name }} </span>-{{ item.al.name }}
            </div>
          </div>
          <!-- 操作区 -->
          <div class="more" v-if="!item.showPopover" @click.stop="item.showPopover = true">
            <van-icon name="ellipsis" />
          </div>
          <van-popover style="width:100px" v-else v-model:show="item.showPopover" :actions="actions" @select="onSelect">
            <template #reference>
              <div class="more">
                <van-icon name="ellipsis" />
              </div>
            </template>
          </van-popover>
        </li>
      </ul>
    </div>
  </div>

  <!-- 分享 -->
  <Share ref="shareRef"></Share>
</template>

<script setup>
import { reactive, toRefs, ref, onMounted } from 'vue'
import { Toast } from 'vant';
import Share from '@/components/share/Share.vue'
import { useRoute } from 'vue-router'
import { storeToRefs } from 'pinia'
import { PlayStore } from '@/store/playlist'
const playStore = PlayStore()
let { playList, playListIndex, updateList } = storeToRefs(playStore);

const $route = useRoute()
const shareRef = ref();
let showLoadingIcon = ref(true);

const props = defineProps({
  playlist: {
    default: []
  },
  songlist: {
    default: []
  }
})


// 初始化数据 
let playListId = $route.query.id
let songs = ref([]);

// 播放歌单指定
const playSong = (songlist, index) => {
  if (songlist.length == 0) return Toast.fail('正在加载歌曲列表')
  playStore.updateList(songlist, index)
}

// 播放全部
const playAll = (songlist) => {
  if (songlist.length == 0) return Toast.fail('正在加载歌曲列表')
  playStore.updateList(songlist)
}


// 点击歌单信息
const msg = (msg) => {
  Toast.success('点击了' + msg);
}

// 点击更多 
let showPopover = ref(false);
let actions = ref([
  { text: '样式问题' },
  { text: '需要' },
  { text: '修改' },
]
)
const hdMore = () => {
  showPopover.value = true;
  Toast.success('点击了更多');

}

const onSelect = () => {

}



defineExpose({
  showLoadingIcon,
})
</script>
  
<style lang='less' scoped>
.van-loading {
  text-align: center;
}

.song-list {
  margin-top: 50px;
  width: 100%;
  background-color: #FFF;
  padding-top: 0;

  .play-info {
    width: 80%;
    margin: 0 auto;
    background-color: #FFF;

    display: flex;
    flex-wrap: nowrap;
    border-radius: 50px;
    justify-content: space-around;
    transform: translateY(-50%);
    box-shadow: 0px 2px 2px #d1d3d3;
    padding: 15px 40px;
    box-sizing: border-box;

    li {
      text-align: center;
      display: flex;
      flex-wrap: nowrap;
      align-items: center;

      .van-icon {
        margin-right: 10px;
      }

      span {
        font-size: 20px;
      }

    }
  }

  .list {
    .title {
      font-weight: bold;

      .play-all {
        display: flex;
        align-items: center;
      }

      span {
        font-size: 30px;
        margin-left: 20px;
      }
    }

    ul {
      margin-top: 20px;
      font-size: .5rem;

      li {
        margin: 30px 0;
        display: flex;
        flex-wrap: nowrap;
        justify-content: space-between;
        align-items: center;

        .index {
          width: 10%;
          // color: #959595;
        }

        .song-detail {
          flex: 1;

          .song-info {
            font-size: 20px;
            margin-top: 10px;
          }


        }

        .more {
          width: 100px;
          text-align: center;
        }
      }
    }
  }
}
</style>